package com.awan.controller;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class StickerCategoryItem {
	
	public String id;
	public String name;
	public String price;
	public String thumbnail;
	
	private static String TAG = "StickerCategoryItem";
	
	public static List<StickerCategoryItem> fromJsonArrayString(String jsonArrayString) {
		
		List<StickerCategoryItem> result=new ArrayList<StickerCategoryItem>();
		try {
			JSONObject jsonResponse = new JSONObject(jsonArrayString);
			String status = jsonResponse.getString("STATUS");
			if(status.trim().equalsIgnoreCase("SUCCESS")){
				JSONArray users = new JSONArray(jsonResponse.getString("DATA"));				
				for (int i=0;i<users.length();i++) {
					StickerCategoryItem ui=fromJson(users.getJSONObject(i));				
					result.add(ui);
				}
			}else{
				Log.e(TAG, "STATUS "+status);
			}
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e(TAG, "JSONException[fromJsonArrayString]:"+e.getMessage());
			e.printStackTrace();
		}
		return result;
	}
	public static StickerCategoryItem fromJson(JSONObject jsonObject) {
		StickerCategoryItem result=null;
		try {
			//JSONObject data = jsonObject.getJSONObject("DATA");
			//if(data != null){				
				result=new StickerCategoryItem();
				
				result.id	= jsonObject.getString("package_id");
				result.name	= jsonObject.getString("package_name");
				result.price	= jsonObject.getString("package_price");
				result.thumbnail	= jsonObject.getString("package_thumbnail");		
				
			//}else{
			//	Log.e(TAG, "Data null");
			//}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e(TAG, "JSONException[fromJson]:"+e.getMessage());
			e.printStackTrace();
		}
		return result;
	}

}
